package com.ibm.risk.irmp.base.auth.entity;

import com.ibm.risk.irmp.common.audit.Auditable;
import com.ibm.risk.irmp.common.auth.vo.IUserInfoVo;
import com.ibm.risk.irmp.common.auth.vo.LoginUser;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import lombok.Data;

import java.time.LocalDate;

@Data
////@Accessors(chain = true) 不能加这个，否则Spring BeanCopier不能复制
@MappedSuperclass
public class SystemUserBase extends Auditable implements IUserInfoVo {
    @Id
    private String username;
    private String displayName;
    private String userSn;
    private String userType;
    @Enumerated(EnumType.STRING)
    private LoginUser.Status status;
    private String nativeName;
    private String email;
    private String mobile;
    private LocalDate validFrom;
    private LocalDate validTo;
    private String ssoUid;
    private String gender;
    private String idType;
    private String idNumber;
    private LocalDate birthDate;

    @Override
    public Boolean getIsValid() {
        LocalDate dnow = LocalDate.now();
        return (validFrom == null || validFrom.isBefore(dnow)) && ( validTo == null || !validTo.isBefore(dnow));
    }
}
